<?php

/*
  Project: Blogmer - Open Source Blogging Software
  Type: PHP
  Desc: Contains all settings of blog.
  Author: Yashpal
  Usage:  	$this->load->model('Settings_model','',TRUE);
			$this->Settings_model->Blog_Settings();  - get settings value from database
			

  Function name : 
  Blog_Settings   -> This function will give the blog settings values.
 

*/


class Sidebar_model extends Model 
{
    function Sidebar_model()
    { parent::Model();}
	
	
	function _array_to_list($input,$ul_id)
	{
		$list = array_unique($input);
	 	$attributes = array(
                    'class' => 'sidemenu',
                    'id'    => $ul_id
                    );

		$result= ul($list, $attributes);
		return $result;
	}
	function archives_list()
	{
	 	$query = $this->db->query('select DISTINCT PostedDate from posts');
	 
	 	if($query->num_rows()<=0)
		  return 'No Archive Present';
		$input=array();
  	 	foreach ($query->result() as $row)
	 	{ 
	   		$input[]= anchor('blog/archives/'.substr($row->PostedDate,0,7),date("F Y ",strtotime($row->PostedDate)));
	 	}

	 	return self::_array_to_list($input,'archive_list');
	}
	
	function recent_posts($posts=10)
	{
		//$data="<ul class=\"sidemenu\">";
		$this->db->limit($posts);
		$this->db->order_by("PostID", "desc"); 
		$query = $this->db->get('posts');
		if($query->num_rows()<=0)
		  return 'No recent posts are available at this time';
		
		$input=array();
		foreach ($query->result() as $row)
		{
			if($row->Status==1)
			$input[]= anchor("blog/post/".url_title($row->Title),$row->Title);
		}	
		
		return self::_array_to_list($input,'recent_posts');
	}
	
	function categories_list()
	{
		$query = $this->db->get('categories');
		$strr=array();
		foreach ($query->result() as $row)
			$strr[]=anchor('blog/category/'.$row->Cat,$row->Cat);
		return self::_array_to_list($strr,'categories_list');
	}
	
	function recent_comments($number=10)
	{
		$this->db->limit($number);	
		$this->db->order_by("CommentID", "desc"); 
		$query = $this->db->get('comments');
		$strr="";
		if($query->num_rows()<0)
		{ return "";
		}
		else
		{
		    foreach ($query->result() as $row)
			{   
				if($row->MemberName=="")//guest comment
					$strr[]=anchor('blog/post/'.$row->URLTitle.'#comments'.$row->CommentID,substr($row->Content,0,200)."... by <strong>".$row->GuestName."</strong>");
				else//member comment
					$strr[]=anchor('blog/post/'.$row->URLTitle.'#comments'.$row->CommentID,substr($row->Content,0,200)."... by <strong>".$row->MemberName."</strong>");
				
			 
			 }		
		  }	
		  
		  return self::_array_to_list($strr,'recent_comments');
		 
	}
	
	

}// end of class
		
?>